
import Express from "express"
import { ContentServers } from '../../server/content'

const RouterContent = Express.Router();

RouterContent.post('/', async (req, res) => {
    const addRes = await ContentServers.add(req.body);

    if(Array.isArray(addRes)) {
        const errData = addRes.join(';')
        res.send({
            err: errData,
            data: '',
            status: "失败"
        })
    } else {
        res.send({
            err: '',
            data: addRes,
            status: "成功"
        })
    }
})

// RouterContent.delete('/:id', async (req, res) => {
    // const deleteData = await MovieServers.delete(req.params.id);
    // res.send({
        // data: deleteData,
        // status: `删除了${deleteData.deletedCount}条数据`
    // })
// })
// 
RouterContent.put('/:id', async (req, res) => {
    const editData = await ContentServers.edit(req.params.id, req.body)
    res.send({
        data: editData
    })
})


RouterContent.get('/:id', async (req, res) => {
    const findOne = await ContentServers.find(req.params.id);
    res.send({
        data: findOne,
        status: 'success'
    })
})

RouterContent.get('/', async (req, res) => {
    const queryData = await ContentServers.findMore(req.query)

    res.send({
        data: queryData
    })
})

RouterContent.get('/navNum', async (req, res) => {
    const queryData = await ContentServers.findMore(req.query)

    res.send({
        data: queryData
    })
})


export { RouterContent }